#include "uti_barseries_mq.h"
#include "uti_interface.h"
#include "uti_consolecolor.h"

BarSeries_Mq::BarSeries_Mq(BarSerInfo* pserinfo, HANDLE* phan):m_phan_callback(phan)
{

	if (!GetBarSeries(pserinfo, &m_pser))
	{
		SetConsoleColor(FOREGROUND_GREEN);  
		cerr<<"[BarSeries_Mq] GetBarSeries Failed"<<endl;
		SetConsoleColor(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);  

		return;

	}

	m_pstart = (m_pser->m_pcur - m_pser->m_index);

	m_index = 0;

	if (NULL != m_phan_callback)
		*m_phan_callback = CreateEvent(NULL, false, false, NULL);

	m_size = m_pser->m_serinfo.sersize;
};

BarSeries_Mq::~BarSeries_Mq()
{
	if (NULL != m_pser)
		delete m_pser;

	if (NULL != m_phan_callback)
		CloseHandle(*m_phan_callback);
};

int BarSeries_Mq::Checkindex()
{
	int ret = 0;

	m_index++;

	if (m_index == m_size)
	{
		if (NULL != m_phan_callback)
			SetEvent(*m_phan_callback);

		m_index = 0;

		ret = 1;
	}

	return ret;

}